<!DOCTYPE HTML>
<html>

<head>
    <title>sparks-bigfire</title>
    <meta name="viewport" id="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <meta charset="utf-8">
    <style type="text/css">
        body {
            font-family: Monospace;
            background-color: #f0f0f0;
            margin: 0px;
            overflow: hidden;
        }
        
        #testCanvas {
            background: #000000;
        }
    </style>
</head>

<body>
    <canvas id="testCanvas"></canvas>
    <script src="../../lib/requestAnimationFrame.min.js"></script>
    <script src="../../lib/stats.min.js"></script>
    <script src="//localhost:3001/build/proton.js"></script>
    <script>
        var canvas;
        var context;
        var proton;
        var renderer;
        var emitter;
        var stats;

        Main();

        function Main() {
            canvas = document.getElementById("testCanvas");
            canvas.width = window.innerWidth;
            canvas.height = window.innerHeight;
            context = canvas.getContext('2d');
            context.globalCompositeOperation = "lighter";
            
            addStats();
            loadImage();
        }

        function addStats() {
            stats = new Stats();
            stats.setMode(2);
            
            stats.domElement.style.position = 'absolute';
            stats.domElement.style.left = '0px';
            stats.domElement.style.top = '0px';
            document.body.appendChild(stats.domElement);
        }

        function loadImage() {
            var image = new Image()
            image.onload = function(e) {
                createProton(e.target);
                tick();
            }
            image.src = 'image/fire.png';
        }

        function createProton(image) {
            proton = new Proton;
            emitter = new Proton.Emitter();
            emitter.rate = new Proton.Rate(new Proton.Span(5, 13), .1);
            
            emitter.addInitialize(new Proton.Mass(1));
            emitter.addInitialize(new Proton.Body(image));
            emitter.addInitialize(new Proton.P(new Proton.CircleZone(canvas.width / 2, canvas.height / 2 + 200, 10)));
            emitter.addInitialize(new Proton.Life(5, 7));
            emitter.addInitialize(new Proton.V(new Proton.Span(2, 3), new Proton.Span(0, 30, true), 'polar'));
            
            emitter.addBehaviour(new Proton.Scale(1, .2));
            emitter.addBehaviour(new Proton.Alpha(1, .2));
            emitter.emit();
            proton.addEmitter(emitter);

            renderer = new Proton.CanvasRenderer(canvas);
            proton.addRenderer(renderer);
        }

        function tick() {
            requestAnimationFrame(tick);

            stats.begin();
            proton.update();
            stats.end();
        }
    </script>
</body>

</html>